package team.chess.qieces;

//import com.sun.javaws.IconUtil;

import java.awt.*;

/**
 * 车类
 *
 */
public class Chariot extends Qiece{

    public Chariot(Qiece a,int index,int c){
        if (index == 0){
            this.kind = 4;
            this.x = a.x;
            this.y = a.y;
            this.controller = c;
            this.moveof = 0;
        }else if (index == 1){
            this.kind = a.kind;
            this.controller = a.controller;
        }
        this.scl = 0;
    }

    @Override
    public void paintSelf(Graphics g) {
        if(this.controller == 0 && this.kind !=0){           //为黑子时
            g.drawImage(chariots_b,x,y,null);
        } else if(this.controller == 1 && this.kind !=0){    //为红子时
            g.drawImage(chariots_r,x,y,null);
        }
        if(this.moveof == 1){
            g.drawImage(point,x+10,y+10,null);
        }
    }


    @Override
    public void movingRange(Qiece[] qieces, int row, int col) {
        //右
        for (int h = col+1; row*9+h  < (row+1)*9; h++){
            if (qieces[row*9+h].getKind() != 0){
                if (this.controller != qieces[row*9+h].controller){
                    qieces[row*9+h].setMoveof(1);
                }
                break;
            }else if (qieces[row*9+h].getKind() == 0){
                qieces[row*9+h].setMoveof(1);
            }
        }
        //左
        for (int h = col-1; row*9+h  >= row*9; h--){
            if (qieces[row*9+h].getKind() != 0){
                if (this.controller != qieces[row*9+h].controller){
                    qieces[row*9+h].setMoveof(1);
                }
                break;
            }else if (qieces[row*9+h].getKind() == 0){
                qieces[row*9+h].setMoveof(1);

            }
        }
        //下
        for (int h = row+1; h*9+col < 90; h++){
            if (qieces[h*9+col].getKind() != 0){
                if (this.controller != qieces[h*9+col].controller){
                    qieces[h*9+col].setMoveof(1);
                }
                break;
            }else if (qieces[h*9+col].getKind() == 0){
                qieces[h*9+col].setMoveof(1);
            }
        }
        //上
        for (int h = row-1; h*9+col >= 0; h--){
            if (qieces[h*9+col].getKind() != 0){
                if (this.controller != qieces[h*9+col].controller){
                    qieces[h*9+col].setMoveof(1);
                }
                break;
            }else if (qieces[h*9+col].getKind() == 0){
                qieces[h*9+col].setMoveof(1);
            }
        }
    }
}